from django.contrib import admin

from django.template import RequestContext

from django.shortcuts import render_to_response

from core.admin import ProtectedModelAdmin
from core.utils import render_to

from exams.models import Professor, Executor, SubjectYear, Subject, SubjectProgram
from exams.forms import ExecutorForm

class ProfessorAdmin(ProtectedModelAdmin):
  list_display = ('code', 'last_name', 'first_name', 'inactive',)
  list_editable = ['first_name', 'last_name', 'inactive']
  search_fields = ['code', 'last_name', 'first_name']

class ExecutorAdmin(admin.ModelAdmin):
  list_display = ('professor', 'subject_year',)
  search_fields = ('professor__code', 'professor__last_name', 'professor__first_name', 'subject_year__subject__code', 'subject_year__subject__name', 'subject_year__school_year_start',)
  raw_id_fields = ('professor', 'subject_year', 'cooperates_with',)
  form = ExecutorForm
  add_form_template = 'exams/admin/add_executor.htm'
  change_form_template = 'exams/admin/add_executor.htm'

class SubjectYearAdmin(admin.ModelAdmin):
  list_display = ('subject', 'school_year_start',)
  search_fields = ('subject__code', 'school_year_start',)
  
  def get_model_perms(self, request):
    """Return empty dict, to hide it from index.
    """
    return {}

class SubjectAdmin(ProtectedModelAdmin):
  list_display = ('code', 'name', 'inactive',)
  list_editable = ['name', 'inactive']
  search_fields = ('code', 'name',)

admin.site.register(Professor, ProfessorAdmin)
admin.site.register(Executor, ExecutorAdmin)
admin.site.register(Subject, SubjectAdmin)

# Hidden admins
admin.site.register(SubjectYear, SubjectYearAdmin)
